import axios from 'axios'
import type { AxiosResponse } from 'axios'
import { ElMessage as Message } from 'element-plus/es'
import { CONFIG } from '@/config/config'

// 创建 axios 实例
const request = axios.create({
  baseURL: CONFIG.BASE_API,
  timeout: 10000,
  headers: {
    'Content-Type': 'application/json'
  }
})

// 响应拦截器
request.interceptors.response.use(
  (response: AxiosResponse) => response.data,
  error => {
    Message.error(error.response?.data?.message || '请求失败')
    return Promise.reject(error)
  }
)

export default request 